<html>
<head><meta charset="utf-8"><title>add trait `Takeable` · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html">add trait `Takeable`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211179506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179506">(Sep 24 2020 at 19:34)</a>:</h4>
<p>It would be nice to have a simple trait, <code>Takeable</code> in <code>core</code>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Takeable</span>: <span class="nb">Default</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">take</span><span class="p">(</span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">core</span>::<span class="n">mem</span>::<span class="n">take</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>That could be implemented on all the collections, e.g.:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">Takeable</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Vec</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="211179547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179547">(Sep 24 2020 at 19:34)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> thought this had been proposed before but wasn't sure if it had gone anywhere</p>



<a name="211179645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179645">(Sep 24 2020 at 19:35)</a>:</h4>
<p>considering that <code>Takeable</code> has a bound on <code>Default</code>, what's the advantage over using <code>mem::take</code> directly here?</p>



<a name="211179703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179703">(Sep 24 2020 at 19:36)</a>:</h4>
<p>It's shorter and you don't need to import <code>core::mem</code> :)</p>



<a name="211179718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179718">(Sep 24 2020 at 19:36)</a>:</h4>
<p>It's just for "ergonomics"</p>



<a name="211179750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179750">(Sep 24 2020 at 19:36)</a>:</h4>
<p>Plus it would make it easier to find in docs and it would be consistent with <code>Option::take</code></p>



<a name="211179865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179865">(Sep 24 2020 at 19:37)</a>:</h4>
<p>Someone proposed adding <code>take()</code> to <code>Default</code> in <a href="https://github.com/rust-lang/rust/issues/76633">#76633</a>, but people thought there would be churn because of <code>Default</code>'s wide use</p>



<a name="211179886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179886">(Sep 24 2020 at 19:38)</a>:</h4>
<p>This would avoid that because it would not be auto-implemented</p>



<a name="211179985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211179985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211179985">(Sep 24 2020 at 19:39)</a>:</h4>
<p>but it requires to not be part of prelude in this case</p>



<a name="211180023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180023">(Sep 24 2020 at 19:39)</a>:</h4>
<p>Personally, I'd rather not have both ways here.  And <code>core</code> in general doesn't seem to make things methods just for the sake of them being methods.</p>



<a name="211180024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180024">(Sep 24 2020 at 19:39)</a>:</h4>
<p>or really only be implement for collections, at which point I personally don't feel like it carries its weight</p>



<a name="211180298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180298">(Sep 24 2020 at 19:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60/near/211180023">said</a>:</p>
<blockquote>
<p>Personally, I'd rather not have both ways here.  And <code>core</code> in general doesn't seem to make things methods just for the sake of them being methods.</p>
</blockquote>
<p>What about <code>Option::take</code>?</p>



<a name="211180402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180402">(Sep 24 2020 at 19:42)</a>:</h4>
<p><code>Option::take</code> is inherent.  I should have said "extension methods".</p>



<a name="211180730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180730">(Sep 24 2020 at 19:45)</a>:</h4>
<p>I just mean that there's no reason for it being a method other than not using <code>mem::take</code></p>



<a name="211180745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180745">(Sep 24 2020 at 19:45)</a>:</h4>
<p>I think what we have precedent for right now is specific inherent take methods on types where it makes sense.</p>



<a name="211180893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180893">(Sep 24 2020 at 19:46)</a>:</h4>
<p>But I'm not sure that <code>Csprng::take</code> makes sense to have available as a method, even if it's <code>Default</code> and thus is technically usable with <code>mem::take</code>.</p>



<a name="211180906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180906">(Sep 24 2020 at 19:46)</a>:</h4>
<p>I just think it makes sense on <code>Vec</code>, and <span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> thought that the reason it wasn't there is we didn't want to implement it one by one on all the collections</p>



<a name="211180971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211180971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211180971">(Sep 24 2020 at 19:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60/near/211180893">said</a>:</p>
<blockquote>
<p>But I'm not sure that <code>Csprng::take</code> makes sense to have available as a method, even if it's <code>Default</code> and thus is technically usable with <code>mem::take</code>.</p>
</blockquote>
<p>Where is that from?</p>



<a name="211181834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/add%20trait%20%60Takeable%60/near/211181834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/add.20trait.20.60Takeable.60.html#211181834">(Sep 24 2020 at 19:55)</a>:</h4>
<p>A conceptual type that seeds itself from <code>/dev/random</code> in <code>Default</code> -- that's a reasonable <code>Default</code>, but also not a good fit with <code>take</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>